import axios from 'axios'

/**
 * 对应后端接口: POST /api/ratings
 * 提交/更新用户对模板的评分和评论
 * @param {object} ratingData - 包含 userId, papercutId, ratingValue, reviewText
 */
export const submitRatingApi = (ratingData) => {
  // 注意：前端传入的应该是 { user: { id: userId }, papercut: { id: papercutId }, ... }
  // 才能与后端 TemplateRating 实体匹配
  const dataToSend = {
    user: { id: ratingData.userId },
    papercut: { id: ratingData.templateId },
    ratingValue: ratingData.ratingValue,
    reviewText: ratingData.reviewText,
  }
  return axios.post('/api/ratings', dataToSend)
}
